{% extends 'base.html' %}
{% include 'link_css.html' %}
{% block content %}


<div class="text-center">
<form  class="col-lg-12" action="{% url 'build_go' %}" method="get">

 <fieldset class="form-group">
    <label for="formGroupExampleInput">运行环境</label>
    <select id="env" class="selectpicker form-control" data-live-search="true" name="env"  onchange="getoption(this.value)">
      <option value="none"></option>
      <option value="1">生产环境</option>
      <option value="2">测试环境</option>
    </select>
 </fieldset>

 <fieldset class="form-group">
    <label for="formGroupExampleInput">部署主机</label>
    <select id="hostname" class="selectpicker form-control" data-live-search="true" name="hostname">
    </select>
 </fieldset>

 <fieldset class="form-group">
    <label for="formGroupExampleInput">go 项目名称</label>
    <input type="text" class="form-control" id="formGroupExampleInput" placeholder="spike" name="project" required="">
  </fieldset>
  <fieldset class="form-group">
    <label for="formGroupExampleInput2">supervisor运行程序名称</label>
    <input type="text" class="form-control" id="formGroupExampleInput2" placeholder="spike_shops" name="supervisorname" required="">
  </fieldset>
  <fieldset class="form-group">
    <label for="formGroupExampleInput3">go运行命令</label>
    <input type="text" class="form-control" id="formGroupExampleInput3" placeholder="spike shops -c config.toml" name="command" required="">
  </fieldset>
  <fieldset class="form-group">
    <label for="formGroupExampleInput4">svn项目地址</label>
    <input type="text" class="form-control" id="formGroupExampleInput3" placeholder="http://svn.abc.com/svn/spike" name="svnrepo" required="">
  </fieldset>
  <fieldset class="form-group">
    <label for="formGroupExampleInput5">svn用户名</label>
    <input type="text" class="form-control" id="formGroupExampleInput4" placeholder="username" name="svnusername" required="">
  </fieldset>
  <fieldset class="form-group">
    <label for="formGroupExampleInput6">svn密码</label>
    <input type="text" class="form-control" id="formGroupExampleInput5" placeholder="password" name="svnpassword" required="">
  </fieldset>


    <input  id="sub" class="btn btn-danger" type="submit" value="Deploy" disabled="disabled">
</form>
</div>


<script>
    function getoption(val) {


        var env = document.getElementById("env").value;
        var select = document.getElementById("hostname");


        select.options.length = 0;   // del options
        if (env != "none") {
            $.getJSON("/asset/getBuildList",{"env":env},function (result) {
                //console.log(result)
                for (i=0;i<result.length;i++) {
                    var objOption = document.createElement("OPTION")
                    objOption.value = result[i]
                    objOption.text = result[i]
                    select.add(objOption)
                }
                if (result.length != 0) {
                    $("#sub").attr("disabled", false)
                }
                else{
                    $("#sub").attr("disabled", true)
                }
                console.log(result.length)
            })
        }
        else{
            $("#sub").attr("disabled", true)
        }
    }
</script>
{% endblock %}
